﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using SAASInvest.Contracts;
using System.IO;

namespace SAASInvest.ConsoleHost
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
    public class Controller : IController
    { 
        public void UploadFile(FileUploadStream uploadStream)
        {
            Console.WriteLine("Upload File");
            //if (uploadStream.UploadStream != null && uploadStream.UploadStream.CanRead)
            //{
            //    string fileName = uploadStream.FileName;
            //    string fileFullName = Path.Combine(Environment.CurrentDirectory, @"Upload\" + fileName); 
            //    Stream sourceStream = uploadStream.UploadStream;
            //    using (FileStream targetWriter = new FileStream(fileFullName, FileMode.CreateNew, FileAccess.Write))
            //    {
            //        const int bufferLength = 4096;
            //        byte[] buffer = new byte[bufferLength];
            //        int count = 0;
            //        while ((count = sourceStream.Read(buffer, 0, bufferLength)) > 0)
            //        {
            //            targetWriter.Write(buffer, 0, count);
            //        }
            //        targetWriter.Close();
            //    }
            //    sourceStream.Close();
            //}
        }


        public void UploadData(FileUploadData uploadData)
        {
            throw new NotImplementedException();
        }
    }
}
